package need_learn.coding.ali;

import java.util.Iterator;
import java.util.LinkedList;
/**
 * TODO 阿里，单链表反转 ps：本解法借助了 LinkedList自带方法 addFirst()
 *
 * @author david
 * @version 1.0
 * @date 2021/4/20 14:56
 */
public class NodeListReverse {
    //链表反转
    public static void main(String[] args) {
        reverse();
    }

    public static void reverse() {
        LinkedList<Integer> list = new LinkedList<>();
        LinkedList<Integer> templist = new LinkedList<>();
        int i = 0;
        while (i < 6) {
            list.add(i);
            i++;
        }
        Iterator<Integer> it = list.iterator();
        int m;
        while (it.hasNext()) {
            m = it.next();
            //addFirst 是核心``
            templist.addFirst(m);
        }
        list = templist;
        System.out.println(list);
    }
}
